package com.djzhou.gmms.role.action;

import java.util.Iterator;
import java.util.List;

import com.djzhou.gmms.base.action.BaseAction;
import com.djzhou.gmms.model.authority.TbAuthority;
import com.djzhou.gmms.model.menu.TbMenu;
import com.djzhou.gmms.model.menu.TbMenuAuthority;
import com.djzhou.gmms.model.role.RoleMenuAuthorityVo;
import com.djzhou.gmms.model.role.TbRole;
import com.djzhou.gmms.model.role.TbRoleAuthority;
import com.opensymphony.xwork2.ModelDriven;

public class RoleAuthorityAction extends BaseAction<TbRoleAuthority> implements ModelDriven<TbRoleAuthority> {

	private TbRoleAuthority roleAuthority;
	private List<TbRole> roleList;
	private Integer roleId;
	private List<TbRoleAuthority> roleAuthorityList;
	private List<TbMenuAuthority> menuAuthorityList;
	private Integer menuId;
	private List<TbMenu> menuList;
	private List<TbAuthority> authorityList;
	private List<RoleMenuAuthorityVo> voList;
	
	private Integer menuAuthorityRoleId;//角色权限-下拉框中的角色ID值
	private String menuAuthorityString;//角色权限复选框组成的字符串 单号索引为菜单ID 双号索引为权限ID

	@Override
	public String save() {
		roleAuthorityService.save(menuAuthorityString, menuAuthorityRoleId, queryUser());
		return SUCCESS;
	}

	@Override
	public String toEdit() {
		roleList=roleService.queryList(queryCompany().getCompanyId());
		menuList=menuService.queryList(queryCompany().getCompanyId(), queryDepartment().getDepartmentId(), 0);
		authorityList=authorityService.queryDefaultAuthorityList();
		menuAuthorityList=menuAuthorityService.queryList();
//		voList=roleAuthorityService.queryRoleMenuAuthorityVoList(roleId);
		return SUCCESS;
	}
	
	public String queryRoleAuthority(){
		msg="";
		List<TbRoleAuthority> raList=roleAuthorityService.queryList(menuAuthorityRoleId);
		for(Iterator<TbRoleAuthority> i = raList.iterator(); i.hasNext();){
			TbRoleAuthority ra=i.next();
			msg+=ra.getMenu().getMenuId()+","+ra.getAuthority().getAuthorityId()+"#";
		}
		if(!msg.equals(""))msg=msg.substring(0,msg.length()-1);
		return SUCCESS;
	}

	public TbRoleAuthority getModel() {
		return roleAuthority;
	}

	public TbRoleAuthority getRoleAuthority() {
		return roleAuthority;
	}

	public void setRoleAuthority(TbRoleAuthority roleAuthority) {
		this.roleAuthority = roleAuthority;
	}

	public List<TbRole> getRoleList() {
		return roleList;
	}

	public void setRoleList(List<TbRole> roleList) {
		this.roleList = roleList;
	}

	public Integer getRoleId() {
		return roleId;
	}

	public void setRoleId(Integer roleId) {
		this.roleId = roleId;
	}

	public List<TbRoleAuthority> getRoleAuthorityList() {
		return roleAuthorityList;
	}

	public void setRoleAuthorityList(List<TbRoleAuthority> roleAuthorityList) {
		this.roleAuthorityList = roleAuthorityList;
	}

	public List<TbMenuAuthority> getMenuAuthorityList() {
		return menuAuthorityList;
	}

	public void setMenuAuthorityList(List<TbMenuAuthority> menuAuthorityList) {
		this.menuAuthorityList = menuAuthorityList;
	}

	public Integer getMenuId() {
		return menuId;
	}

	public void setMenuId(Integer menuId) {
		this.menuId = menuId;
	}

	public List<TbMenu> getMenuList() {
		return menuList;
	}

	public void setMenuList(List<TbMenu> menuList) {
		this.menuList = menuList;
	}

	public List<TbAuthority> getAuthorityList() {
		return authorityList;
	}

	public void setAuthorityList(List<TbAuthority> authorityList) {
		this.authorityList = authorityList;
	}

	public Integer getMenuAuthorityRoleId() {
		return menuAuthorityRoleId;
	}

	public void setMenuAuthorityRoleId(Integer menuAuthorityRoleId) {
		this.menuAuthorityRoleId = menuAuthorityRoleId;
	}

	public String getMenuAuthorityString() {
		return menuAuthorityString;
	}

	public void setMenuAuthorityString(String menuAuthorityString) {
		this.menuAuthorityString = menuAuthorityString;
	}

	public List<RoleMenuAuthorityVo> getVoList() {
		return voList;
	}

	public void setVoList(List<RoleMenuAuthorityVo> voList) {
		this.voList = voList;
	}
	

	

}
